﻿''' <Name>Character Class</Name>
''' <Owner>Celerian Rainquest</Owner>
''' <Date>3/27/2012</Date>
''' <Summary>Basic Character constructor.</Summary>

Public Class Character
    Inherits Entity

    Private _enumNextAction As MovementDirection = MovementDirection.NONE
    Private _lHealth As Int32 = 1

    Dim sName As String
    Protected iBaseHealth, iBaseMana As Integer
    Protected iBaseStr, iBaseAgi, iBaseVit, iBaseInt, iBaseChr, iBaseSan, iBasePer, iBaseLuk As Integer
    Protected iPlusStrMod, iPlusAgiMod, iPlusVitMod, iPlusIntMod, iPlusChrMod, iPlusSanMod, iPlusPerMod, iPlusLukMod As Integer
    Protected iMinusStrMod, iMinusAgiMod, iMinusVitMod, iMinusIntMod, iMinusChrMod, iMinusSanMod, iMinusPerMod, iMinusLukMod As Integer
    Dim iLevel, iTotHealth, iCurHealth, iTotMana, iCurMana As Integer
    Dim Str, Agi, Vit, Int, Chr, San, Per, Luk As Integer

    Private m_Inventory As New List(Of Item)

    Public Property Inventory As List(Of Item)
        Get
            Return m_Inventory
        End Get
        Set(ByVal value As List(Of Item))
            m_Inventory = value
        End Set
    End Property
    Public Property NextAction As MovementDirection
        Get
            Return _enumNextAction
        End Get
        Set(ByVal value As MovementDirection)
            _enumNextAction = value
        End Set
    End Property


    'Str - Strength     - Effects Melee Damage
    'Agi - Agility      - Movement Speed and Accuracy
    'Vit - Vitality     - Hitpoints and Resilience to special damage
    'Int - Intellect    - Mana, and spellpower
    'Chr - Presence     - Influences social skills, shop prices, NPC reaction
    'San - Sanity       - Measure of mental resistance to pain, fear
    'Per - Perception   - Ability to detect traps, examine
    'Luk - Luck         - Sometimes all you need is a little luck...



    Public Sub setCharacterAttributes(ByVal sCharacterName As String)
        sName = sCharacterName
        iLevel = 1

        'Roll for Base Stats. These should probably never be modified.
        'Base Stats have a range of 3-10. Modifiers may raise/lower min/max potentials.

        iBaseStr = Roll(2 + iPlusStrMod, 10 + iMinusStrMod) + 1
        iBaseAgi = Roll(2 + iPlusAgiMod, 10 + iMinusAgiMod) + 1
        iBaseVit = Roll(2 + iPlusVitMod, 10 + iMinusVitMod) + 1
        iBaseInt = Roll(2 + iPlusIntMod, 10 + iMinusIntMod) + 1
        iBaseChr = Roll(2 + iPlusChrMod, 10 + iMinusChrMod) + 1
        iBaseSan = Roll(2 + iPlusSanMod, 10 + iMinusSanMod) + 1
        iBasePer = Roll(2 + iPlusPerMod, 10 + iMinusPerMod) + 1
        iBaseLuk = Roll(2 + iPlusLukMod, 10 + iMinusLukMod) + 1

        'Implement Vitality effects
        iBaseHealth = Roll(29, 50) + 1

        'Implement Intellect effects
        iBaseMana = Roll(29, 50) + 1


        'Set up working variables. These will change over the course of the game.
        Str = iBaseStr
        Agi = iBaseAgi
        Vit = iBaseVit
        Int = iBaseInt
        Chr = iBaseChr
        San = iBaseSan
        Per = iBasePer
        Luk = iBaseLuk
        iTotHealth = iBaseHealth * Vit
        iCurHealth = iTotHealth
        iTotMana = iBaseMana * Int
        iCurMana = iTotMana

        Dim Inventory As New List(Of Item)
        Inventory.Capacity = 50
    End Sub

    Public Sub showStatusInfo()
        CharacterInfo.lblName.Text = sName
        CharacterInfo.lblLevel.Text = iLevel
        CharacterInfo.lblHealth.Text = iCurHealth & "/ " & iTotHealth
        CharacterInfo.lblMana.Text = iCurMana & "/ " & iTotMana
        CharacterInfo.lblStr.Text = Str
        CharacterInfo.lblAgi.Text = Agi
        CharacterInfo.lblVit.Text = Vit
        CharacterInfo.lblInt.Text = Int
        CharacterInfo.lblChr.Text = Chr
        CharacterInfo.lblSan.Text = San
        CharacterInfo.lblPer.Text = Per
        CharacterInfo.lblLuk.Text = Luk
    End Sub

    Public Sub addLevel()
        iLevel = iLevel + 1

        'Roll for Stat Increase from 1 through BaseStat / 2 (Max Range: 1 - 5)
        Str = Str + (Roll(0, iBaseStr * 0.5) + 1)
        Agi = Agi + (Roll(0, iBaseAgi * 0.5) + 1)
        Vit = Vit + (Roll(0, iBaseVit * 0.5) + 1)
        Int = Int + (Roll(0, iBaseInt * 0.5) + 1)
        Chr = Chr + (Roll(0, iBaseChr * 0.5) + 1)
        San = San + (Roll(0, iBaseSan * 0.5) + 1)
        Per = Per + (Roll(0, iBasePer * 0.5) + 1)
        Luk = Luk + (Roll(0, iBaseLuk * 0.5) + 1)

        iTotHealth = iBaseHealth * Vit
        iCurHealth = iTotHealth
        iTotMana = iBaseMana * Int
        iCurMana = iTotMana
    End Sub

    Public Sub addEquipBonus(ByVal EquipStrMod As Integer, ByVal EquipAgiMod As Integer, ByVal EquipVitMod As Integer, ByVal EquipIntMod As Integer, _
                             ByVal EquipChrMod As Integer, ByVal EquipSanMod As Integer, ByVal EquipPerMod As Integer, ByVal EquipLukMod As Integer)
        'Apply EquipBonus to Stats
        Str = Str + EquipStrMod
        Agi = Agi + EquipAgiMod
        Vit = Vit + EquipVitMod
        Int = Int + EquipIntMod
        Chr = Chr + EquipChrMod
        San = San + EquipSanMod
        Per = Per + EquipPerMod
        Luk = Luk + EquipLukMod

        'Recalculate derivitive stats
        iTotHealth = iBaseHealth * Vit
        iTotMana = iBaseMana * Int
    End Sub

    Public Sub removeEquipBonus(ByVal EquipStrMod As Integer, ByVal EquipAgiMod As Integer, ByVal EquipVitMod As Integer, ByVal EquipIntMod As Integer, _
                                ByVal EquipChrMod As Integer, ByVal EquipSanMod As Integer, ByVal EquipPerMod As Integer, ByVal EquipLukMod As Integer)
        'Apply EquipBonus to Stats
        Str = Str - EquipStrMod
        Agi = Agi - EquipAgiMod
        Vit = Vit - EquipVitMod
        Int = Int - EquipIntMod
        Chr = Chr - EquipChrMod
        San = San - EquipSanMod
        Per = Per - EquipPerMod
        Luk = Luk - EquipLukMod

        'Recalculate derivitive stats
        iTotHealth = iBaseHealth * Vit
        iTotMana = iBaseMana * Int
    End Sub




    Public Sub New()
        _pointLocation = New Point(50, 50)
        _lMovementRate = 10
        _sID = "User"

        Try
            _bitmapImage = New Bitmap(Application.StartupPath & "\Images\player.bmp")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly, String.Format("Class: {0}", Me.GetType().Name))
            _bitmapImage = New Bitmap(10, 10)
        End Try
    End Sub

    ''' <summary>
    ''' A constructor that takes in all the important bits of information to show the image on the screen.
    ''' </summary>
    ''' <param name="startingLocation"></param>
    ''' <param name="movementRate"></param>
    ''' <param name="imageLocation"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal startingLocation As Point, ByVal movementRate As Int32, ByVal imageLocation As String)
        _pointLocation = startingLocation
        _lMovementRate = movementRate
        _bitmapImage = New Bitmap(imageLocation)
        _sID = "User"
    End Sub

    '-- Sets up drawing the image.  
    Public Overrides Sub Paint(ByVal e As System.Drawing.Graphics)
        e.DrawImage(_bitmapImage, _pointLocation)
    End Sub

    Public Overrides Function ProcessState() As Boolean
        '-- The only state the user needs to worry about is which direction the user wants to move.
        Return DoMovement(_enumNextAction)
    End Function

    ''' <summary>
    ''' Takes the information from the user's key press and update the location.
    ''' </summary>
    ''' <param name="direction"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function DoMovement(ByVal direction As MovementDirection) As Boolean
        Dim bMoveOccured As Boolean = False

        If _enumNextAction <> MovementDirection.NONE Then
            Select Case direction
                Case MovementDirection.UP
                    If _pointLocation.Y - _lMovementRate >= 0 Then '-- make sure user is not moving off the screen 
                        _pointLocation.Y -= _lMovementRate
                        bMoveOccured = True
                    Else
                        _enumNextAction = MovementDirection.NONE
                    End If
                Case MovementDirection.DOWN
                    If _pointLocation.Y + _bitmapImage.Height + _lMovementRate < _lScreenHeight Then '-- make sure user is not moving off the screen 
                        _pointLocation.Y += _lMovementRate
                        bMoveOccured = True
                    Else
                        _enumNextAction = MovementDirection.NONE
                    End If
                Case MovementDirection.RIGHT
                    If _pointLocation.X + _bitmapImage.Width + _lMovementRate < _lScreenWidth Then '-- make sure user is not moving off the screen 
                        _pointLocation.X += _lMovementRate
                        bMoveOccured = True
                    Else
                        _enumNextAction = MovementDirection.NONE
                    End If
                Case MovementDirection.LEFT
                    If _pointLocation.X - _lMovementRate >= 0 Then '-- make sure user is not moving off the screen 
                        _pointLocation.X -= _lMovementRate
                        bMoveOccured = True
                    Else
                        _enumNextAction = MovementDirection.NONE
                    End If
                Case Else
                    bMoveOccured = False
            End Select

            If bMoveOccured Then _enumNextAction = MovementDirection.NONE

        End If
        Return bMoveOccured
    End Function

    ''' <summary>
    ''' This shows we can tack more information as we add variables to the print method already in the abstract class.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overloads Function Print() As String
        Return MyBase.Print + String.Format(" Health: {0}", _lHealth)
    End Function
End Class
